export const initState = {
    userInfo:sessionStorage.getItem('userInfo') ? JSON.parse(sessionStorage.getItem('userInfo')) :{} ,
}

export const reducer = (state,action)=>{
    switch (action.type) {
        case 'changeUserInfo':
            return {
                ...state,
                userInfo:action.userInfo,
            };
        default:
            return state;
    }
}

export const actions = {
    changeUserInfo:(userInfo)=>{
        if(userInfo.token){
            sessionStorage.setItem('userInfo',JSON.stringify(userInfo));
        }else{
            sessionStorage.removeItem('userInfo');
        }
        return ({type:'changeUserInfo',userInfo})
    },
}